<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('个人拜访统计列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>机构名称：</label>
                            <input name="deptId" type="hidden" id="treeId"/>
                            <input name="deptName" onclick="selectDeptTree()" id="treeName" type="text"
                                   placeholder="请选择归属机构" autocomplete="off">
                        </li>
                        <li>
                            <label>营销人员：</label>
                            <input type="text" name="userName"/>
                        </li>
                        <li>
                            <label>客户姓名：</label>
                            <input type="text" name="handName"/>
                        </li>
                        <li>
                            <p>个人状态：</p>
                            <select name="state" th:with="type=${@dict.getType('sys_sts')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>查看排序：</label>
                            <select name="sortTime">
                                <option value="">所有</option>
                                <option value="1">建档时间</option>
                                <option value="3">拜访时间</option>
                            </select>
                        </li>
                        <li>
                            <p>营销结果：</p>
                            <select name="ecardSemResult" th:with="type=${@dict.getType('ecard_sem_result')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li class="select-date">
                            <label>拜访日期： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间" readonly
                                   name="params[startDate]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" readonly
                                   name="params[endDate]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()" >
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var semResultDatas = [[${@dict.getType('ecard_sem_result')}]];
    var hasReservationBusiDatas  = [[${@dict.getType('ecard_has_reservation_busi')}]];
    var sysStsDatas = [[${@dict.getType('sys_sts')}]];
    var prefix = ctx + "merchant/branchPerVisitInfo";

    $(function () {
        var options = {
            url: prefix + "/list",
            exportUrl: prefix + "/export",
            modalName: "个人拜访统计",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '主键ID',
                    visible: false
                },
                {
                    field: 'handName',
                    title: '客户姓名'
                },
                {
                    field: 'userName',
                    title: '营销经理'
                },
                {
                    field: 'coordinate',
                    title: '坐标'
                },
                {
                    field: 'mapAddress',
                    title: '地图地址'
                },
                {
                    field: 'visitPic',
                    title: '拜访图片',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var picsplit = row.visitPic.split(',');
                        var imgUrl = '';
                        for (var picsplitKey in picsplit) {
                            imgUrl += '<img class="img-circle img-xs" data-height="300" data-width="500" data-target="self" src="' +picsplit[picsplitKey] + '"/>'
                        }
                        return imgUrl;
                    }
                },
                {
                    field: 'ecardSemResult',
                    title: '营销结果',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(semResultDatas, value);
                    }
                },
                {
                    field: 'newBusiness',
                    title: '个人新办业务'
                },{
                    field: 'failReason',
                    title: '失败原因'
                },
                {
                    field: 'reminderDate',
                    title: '下次回访提醒日期'
                },
                {
                    field: 'hasReservationBusi',
                    title: '有无业务预约',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(hasReservationBusiDatas, value);
                    }
                },
                {
                    field: 'reservationBusiType',
                    title: '预约业务'
                },
                {
                    field: 'appointmentDate',
                    title: '预约日期'
                },
                {
                    field: 'creationTime',
                    title: '拜访时间'
                },
                {
                    field: 'filingTime',
                    title: '建档时间'
                },
                {
                    field: 'deptName',
                    title: '机构名称'
                },
                {
                    field: 'state',
                    title: '个人状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(sysStsDatas, value);
                    }
                },
                {
                    field: 'visitState',
                    title: '拜访状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    field: 'remark',
                    title: '备注说明'
                }]
        };
        $.table.init(options);
    });

    /* 选择机构树 */
    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/dept/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: url,
            callBack: doSub
        };
        $.modal.openOptions(options);
    }

    function doSub(index, layero) {
        var body = $.modal.getChildFrame(index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    function reset() {
        $('#treeId').val('');
        $.form.reset();
    }

    /* 状态显示 */
    function statusTools(row) {
        if (row.visitState == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
        }
    }

    /* 停用 */
    function disable(id) {
        $.modal.confirm("确认要置为无效吗？", function () {
            $.operate.post("/merchant/info/visit/changeStatus", {"id": id, "state": 0});
        })
    }

    /* 启用 */
    function enable(id) {
        $.modal.confirm("确认要置为有效吗？", function () {
            $.operate.post("/merchant/info/visit/changeStatus", {"id": id, "state": 1});
        })
    }
</script>
</body>
</html>